package androidx.blogger.activities;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.Toast;
import androidx.blogger.BloggerApplication;
import androidx.gdata.blogger.BloggerServer;
import androidx.util.ProgressIndicator;

public abstract class ConnectedActivity extends Activity {
  protected BloggerServer server;
	
	/** Called when the activity is first created. */
	@Override
	public final void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
    server = BloggerApplication.getInstance().getServer();
    if (server == null) {
      longMessage("No blogger server!");
      finish();
    } else {
    	onCreate2(savedInstanceState);
    }
	}
	
	protected abstract void onCreate2(Bundle savedInstanceState);
	
	protected void shortMessage(String msg) {
		Toast toast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
		toast.show();
	}

	protected void longMessage(String msg) {
		Toast toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
		toast.show();
	}
	
  protected ProgressIndicator getProgressIndicator(String msg) {
  	progressMessage = msg;
  	return progressIndicator;
  }
  
  private ProgressDialog progressDialog;
  private String progressMessage;
  private ProgressIndicator progressIndicator = new ProgressIndicator() {
  	
		public void showProgressIndicator() {
			progressDialog = ProgressDialog.show(ConnectedActivity.this, "Blogging", progressMessage);
		}
		public void hideProgressIndicator() {
			progressDialog.dismiss();
		}
  };
	
}
